from libc.stdio cimport *

cimport cython
import numpy as np
cimport numpy as np
 
cdef extern from "stdio.h":
    FILE *fopen(const char *path, const char *mode)
    int fclose(FILE *stream)

cdef extern from "C/covMatrix.h":
    void c_covMatrix(FILE *infile, int n, double *s2)


def covMatrix(filename, int n):
    """
    C包装
    """
    filename_byte_string = filename.encode("UTF-8")
    cdef char* fname = filename_byte_string
 
    cdef FILE* infile
    infile = fopen(fname, "rt")
    if infile == NULL:
        raise FileNotFoundError(2, "No such file or directory: '%s'" % filename)
 
    s2 = np.zeros((n,n),dtype=np.double)
    c_covMatrix(infile, n, <double*> np.PyArray_DATA(s2))
    
    return s2



